#include "runningthread.h"
#include "cpu.h"
#include "breakpointtable.h"


RunningThread::RunningThread(QObject *parent) :
        QThread(parent), cpu(CPU::getInstance()), over(false),
        table(BreakPointTable::getInstance(this)), address(0)
{
}

RunningThread::~RunningThread()
{

}

void RunningThread::setStopAddress(quint32 _address)
{
    address = _address;
}



void RunningThread::run()
{
    over = false;
    while(cpu->getPC() != address)
    {
        mutex.lock();
        if(over)
        {
            mutex.unlock();
            break;
        }
        else
        {
            mutex.unlock();
        }
        if(table->containsBreakPoint(cpu->getPC()))
        {
            break;
        }
        cpu->exec();
    }
}

void RunningThread::stop()
{
    mutex.lock();
    over = true;
    mutex.unlock();
}
